package beans.annotation;

import java.lang.reflect.Method;

/**
 * 在运行时分析处理annotation类型的信息
 * 
 * @author beanstao@gmail.com
 * 
 */
public class AnalysisAnnotation
{

	public static void main(String[] args)
	{
		try
		{
			@SuppressWarnings("unchecked")
			Class<Utility> utility = (Class<Utility>) Class.forName("beans.annotation.Utility");

			boolean isDesc = utility.isAnnotationPresent(Description.class);
			if (isDesc)
			{
				Description description = utility.getAnnotation(Description.class);
				System.out.println("Utility's @Description is : " + description.value());
			}

			Method[] methods = utility.getMethods();
			for (Method method : methods)
			{
				if (method.isAnnotationPresent(Anthor.class))
				{
					Anthor anthor = method.getAnnotation(Anthor.class);
					System.out.println("Utility's method is <" + method.getName() + ">, @anthor's name is " + anthor.name() + ", @anthor's group is " + anthor.group());
				}
			}
		}
		catch (ClassNotFoundException e)
		{
			e.printStackTrace();
		}
	}

}
